<?php

namespace app\common\validate;

use think\Validate;

class User extends Validate
{
    protected $rule = [
        'user_uniid' => 'require|regex:TX16\d\d\d\d\d\d\d\d',
        'user_name' => 'require|max:25',
        'password' => 'require|min:6',
        'password_confirm' => 'require|confirm:password',
        'account_type' => 'in:普通会员,理财会员',
        'password2' => 'require|min:6',
        'password2_confirm' => 'require|confirm:password2',
        'mail_address' => 'email',
        'bank_name' => 'require|notin:请选择',
        'card_number' => 'require|checkcardnumber:19',
        'card_name' => 'require|confirm:user_name',
        'province' => 'require',
        'city' => 'require',
        'id_number' => 'require|length:18',
        'phone' => 'require|length:11',
    ];
    protected $message = [
      'user_uniid.require' => '请填写会员编号',
      'user_uniid.regex' => '会员编号格式不正确',
      'user_name.require' => '请输入您的会员昵称',
      'user_name.max' => '用户名最大为25位',
      'password.require' => '请输入密码',
      'password.min' => '密码最小为6位',
      'password_confirm' => '两次密码不匹配',
      'account_type' => '请选择会员等级',
      'password2.require' => '请输入二级密码',
      'password2.min' => '二级密码最小为6位',
      'password2_confirm' => '二级密码不匹配',
      'mail_address' => '请输入正确的邮件地址',
      'bank_name' => '请选择银行名',
      'card_name' => '开户人需和昵称相同',
      'province' => '请选择省份',
      'card_number.require' => '请输入银行卡号',
      'city' => '请选择城市',
      'id_number' => '请输入正确的身份证号',
      'phone' => '请输入正确的手机号',
    ];
    protected $scene = [

    'reg' => ['user_uniid', 'user_name', 'password', 'password_confirm', 'account_type', 'password2', 'password2_confirm', 'mail_address', 'bank_name', 'card_name', 'province', 'city', 'id_number', 'phone'],
    'changepwd' => ['password', 'password_confirm'],
    'changepwd2' => ['password2', 'password2_confirm'],
    'admin' => [ 'user_name', 'password', 'password_confirm', 'account_type', 'password2', 'password2_confirm'],
    'changeinfo' => ['bank_name', 'card_name', 'province', 'city', 'card_number', 'card_sub_bank', 'id_number', 'phone'],
    ];
    protected function checkcardnumber($value, $rule, $data)
    {
        if (stripos($data['bank_name'], '银行')) {
            if (strlen($value) != 19) {
                return '卡号需为19位数字';
            } else {
                return true;
            }
        } else {
            return true;
        }
    }
    protected function checkSub($value, $rule, $data)
    {
        if (stripos($data['bank_name'], '银行')) {
            if (empty($value)) {
                return '请输入支行名';
            } else {
                return true;
            }
        } else {
            return true;
        }
    }
}
